/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 transitions.cpp

	$Header: /heroes4/transitions.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "transitions.h"

#include "abstract_tile.h"
#include "ptr_cache.h"
#include "transition_mask.h"
// -------------------------------------------------------------------------------
// Unnamed namespace
// -------------------------------------------------------------------------------

namespace
{

	// -------------------------------------------------------------------------------
	// Local private non-const transition mask table
	// -------------------------------------------------------------------------------
	t_transition_set transition_masks[ k_transition_set_size ];
	bool			 g_initialized = false;

} // Unnamed namespace

t_transition_set_group g_transition_masks;


// -------------------------------------------------------------------------------
// global variable: transition masks, and function to initialize them.
// -------------------------------------------------------------------------------
static t_pointer_cache<t_transition_set_array> g_transitions( "transitions" );

t_transition_set_group::t_transition_set_group()
{
	g_initialized = false;
}

void t_transition_set_group::initialize() const
{
	static const char* layer_names[k_transition_set_size] =
	{
		"water_to_land 1", // water set 1
		"water_to_land 1", // water set 2
		"water_to_land 2", // water set 3
		"water_to_land 2", // water set 4
		"water_to_land 3", // water set 5
		"land_to_water 1", // land to water 1
		"land_to_water 1", // land to water 2
		"land_to_water 2", // land to water 3
		"land_to_water 2", // land to water 4
		"land_to_water 3", // land to water 5
		"road 1", // road set 1
		"road 1", // road set 2
		"road 2", // road set 3
		"road 2", // road set 4
		"road 2", // road set 5
		"land 1", // land set 1
		"land 2", // land set 2
		"land 2", // land set 3
		"land 3", // land set 4
		"land 3", // land set 5
	};

	int i, j;
	t_cached_ptr<t_transition_set_array> transitions = g_transitions.get();

	for (i = 0; i < k_transition_set_size; i++)
	{
		for (j = 0; j < transitions->size(); j++)
		{
			t_transition_set& masks = (*transitions)[j];

			if (stricmp( layer_names[i], masks.get_name().c_str() ) == 0)
			{
				transition_masks[i] = masks;
			}
		}
	}
	g_initialized = true;
}

t_transition_set const& t_transition_set_group::operator[]( int arg ) const
{
	if (!g_initialized)
		initialize();
	return transition_masks[arg];
}
